package com.liankuan.console.controller.vo.request;

import com.liankuan.console.dto.Exchange;
import com.liankuan.console.dto.StrategyExchange;
import lombok.Data;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@Data
public class StrategyAddExchangeVO {
    private List<Integer> privateExchange;
    private List<AddExchange> totalExchange;

    public StrategyAddExchangeVO(List<StrategyExchange> privateExchange, List<Exchange> totalExchange) {
        this.privateExchange = privateExchange.stream().map(StrategyExchange::getExchangeId).collect(Collectors
                .toList());
        this.totalExchange = totalExchange.stream().map(record -> {
            boolean disabled = false;
            if (this.privateExchange.contains(record.getId())) {
                disabled = true;
            }
            return new AddExchange(record, disabled);
        }).collect(Collectors.toList());
    }

}

@Data
class AddExchange {
    private Integer id;
    private String code;
    private String publicKey;
    private String privateKey;
    private String name;
    private String alias;
    private List<String> coinPairs;
    private Boolean disabled;

    public AddExchange(Exchange exchange, boolean disabled) {
        this.id = exchange.getId();
        this.code = exchange.getCode();
        this.alias = exchange.getAlias();
        this.publicKey = exchange.getPublicKey();
        this.privateKey = exchange.getPrivateKey();
        this.name = exchange.getName();
        this.coinPairs = getPairs(exchange.getCoinPairs());
        this.disabled = disabled;
    }

    private List<String> getPairs(String pairs) {
        return Arrays.stream(pairs.split(",")).collect(Collectors.toList());
    }

}



